package com.mp.dao;

import com.mp.db.jpa.modelo.Item;
import com.mp.db.jpa.modelo.TipoItem;
import com.mp.db.jpa.util.JPAUtil;
import javax.persistence.Query;
import java.util.List;

public class ItemDAO extends GenericoDAO
{
      
    public Item obterItem(int id)
    {
        Query query =  em.createNamedQuery("Item.findById");
        query.setParameter("id", id);
            
        return (Item)this.getSingleResultOrNull(query);
    }
    
    public Item obterItemPorDesc(String desc) 
    {
        Query query =  em.createNamedQuery("Item.findByDesc");
        query.setParameter("desc", desc);
        
        return (Item)this.getSingleResultOrNull(query);    
    }
    
    public List<Item> obterListaItemPorTipoItem(TipoItem tp) 
    {
        Query query =  em.createNamedQuery("Item.findByTipoItem");
        query.setParameter("idtipoitem", tp.getIdTipoItem());
        
        return query.getResultList();    
    }
    
    
    public void gravarItem(Item it)
    {
        JPAUtil.gravar(it);
    }
   
}
